﻿using SingleUserMall.Authorization.Users;
using SingleUserMall.Commissions;
using SingleUserMall.EntityFramework;
using SingleUserMall.Sms;
using System.Linq;

namespace SingleUserMall.Migrations.SeedData
{
    class DefaultSmsCreator
    {
        private readonly SingleUserMallDbContext _context;

        public DefaultSmsCreator(SingleUserMallDbContext context)
        {
            _context = context;
        }

        public void Create()
        {
            CreateSmsEntity();
        }

        private void CreateSmsEntity()
        {
            User adminUser = _context.Users.FirstOrDefault(u => u.UserName == User.AdminUserName);
            if (adminUser != null)
            {
                //Default sms count
                var count = _context.SmsEntity.Count();
                if (count == 0)
                {
                    _context.SmsEntity.Add(new SmsEntity { Qty=15000});
                }
                _context.SaveChanges();
            }
        }
    }
}
